<template>
  <div class="contain">
    <div class="box1">
      <div class="navBox">
        <div
          class="lists"
          v-for="(item, index) in lists"
          :key="index"
          @click="topClick(index)"
        >
          {{ item }}
        </div>
        <div v-if="token" class="hasToken">
          <el-dropdown trigger="hover">
            <div>
              <el-avatar :src="user.headUrl" size="medium"></el-avatar>
              <span class="username" style="z-index: 0">{{ user.username }}</span>
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item class="clearfix">
                <span @click="goMy">个人中心</span>
              </el-dropdown-item>
              <el-dropdown-item>
                <span @click="logout">退出登录</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <div
          v-else
          @click="login"
          style="float: right; width: 200px; text-align: right"
        >
          登录/注册
        </div>
      </div>
    </div>
    <div class="fixed" @click="yijianfn">
      <i class="el-icon-s-opportunity"></i> 意见反馈
    </div>
    <el-dialog title="感谢您提出意见和建议" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="标题：" :label-width="formLabelWidth">
          <el-input v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="联系方式：" :label-width="formLabelWidth">
          <el-input v-model="form.contact"></el-input>
        </el-form-item>
        <el-form-item label="意见内容：" :label-width="formLabelWidth">
          <el-input type="textarea" :rows="8" v-model="form.content"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogSubmit">确 定</el-button>
      </div>
    </el-dialog>
    <div id="cons">
      <Shouye v-if="activeIndex === 0"></Shouye>
      <Jingdian v-if="activeIndex === 1"></Jingdian>
      <Xianlu v-if="activeIndex === 2"></Xianlu>
      <Jiudian v-if="activeIndex === 3"></Jiudian>
      <Gonglue v-if="activeIndex === 4"></Gonglue>
    </div>
  </div>
</template>

<script>
import Shouye from "@/views/main1/Shouye.vue";
import Jingdian from "@/views/main1/Jingdian.vue";
import Xianlu from "@/views/main1/Xianlu.vue";
import Jiudian from "@/views/main1/Jiudian.vue";
import Gonglue from "@/views/main1/Gonglue.vue";
export default {
  components: {
    Shouye,
    Jingdian,
    Xianlu,
    Jiudian,
    Gonglue,
  },
  data() {
    return {
      lists: ["首页", "景点", "线路", "酒店", "旅游攻略"],
      token: window.localStorage.getItem("token"),
      hover: false,
      activeIndex: 0,
      dialogFormVisible: false,
      formLabelWidth: "120px",
      form: {},
      user: {}
    };
  },
  mounted() {
    this.activeIndex = this.$route.query.activeIndex === undefined ? 0 : +this.$route.query.activeIndex
    this.topClick(this.activeIndex)
    this.push();
    this.getUser();
  },
  methods: {
    getUser () {
      if (this.token) {
        this.$axios({
          method: "post",
          url: '/sys/user/getInfo',
          headers: { token: this.token }
        }).then((res) => {
          if (res.data.code !== 0) {
            this.$message.error(res.data.msg)
            return false
          }
          this.user = res.data.page
          return true
        });
      }
    },
    push() {
      // console.log(this.token);
      if (this.token) {
        this.$axios({
          method: "post",
          url: "/sys/user/getRole",
          headers: { token: this.token },
        }).then((res) => {
          if (res.data.code === 0) {
            if (res.data.roleId === 1) {
                this.$router.push("/manage");
              }
            if (res.data.roleId === 2) {
              this.$router.push("/business");
            }
          } else {
            this.$message({
              type: "error",
              message: res.data.msg,
            });
          }
        });
      }
    },
    dialogSubmit() {
      this.dialogFormVisible = false;
      // console.log(this.form);
      this.$axios({
        method: "post",
        url: "/feedback/submit",
        headers: { token: this.token },
        data: this.form,
      }).then((res) => {
        // console.log('意见');
        // console.log(res);
        if (res.data.code === 0) {
          this.$message({
            type: "success",
            message: "提交成功!",
          });
          this.form = {};
        }
        if (res.data.code !== 0) {
          this.$message.error(res.data.msg);
          return false;
        }
      });
    },
    yijianfn() {
      this.dialogFormVisible = true;
    },
    // getInfo() {},
    login() {
      this.$router.push("/login");
    },
    async logout() {
      this.$confirm("确认退出?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          window.localStorage.removeItem("token");
          this.token = window.localStorage.getItem("token");
          this.$message({
            type: "success",
            message: "退出成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    topClick(index) {
      this.activeIndex = index;
      let lists = document.getElementsByClassName("lists");
      lists.forEach((el) => {
        el.style.backgroundColor = "#6ac5b9";
      });
      lists[index].style.backgroundColor = "rgb(162, 236, 174)";
    },
    goMy() {
      this.$router.push("/myinfo");
    },
  },
};
</script>
<style  scoped>
#contain {
  padding: 0;
  margin: 0;
}
.box1 {
  height: 40px;
  background-color: #6ac5b9;
  line-height: 40px;
}
.navBox {
  width: 1200px;
  margin: 0 auto;
}
.lists {
  display: inline-block;
  width: 100px;
  border-right: 1px solid #ccc;
  text-align: center;
}
.lists:hover {
  background-color: #24ac9a;
}
.hasToken {
  display: flex;
  justify-content: space-around;
  align-items: center;
  float: right;
  width: 200px;
  height: 40px;
  position: relative;
}
.touxiang {
  display: inline-block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #777;
  margin: 0 20px;
}
.txhover {
  width: 110px;
  height: 150px;
  position: absolute;
  top: 40px;
  right: 0;
  border: 1px solid rgb(233, 230, 230);
  border-bottom: none;
  border-top: none;
  box-sizing: border-box;
}
.txhover li {
  width: 108px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  border-bottom: 1px solid rgb(233, 230, 230);
  cursor: pointer;
}
.txhover li:hover {
  background-color: #ace;
}
#cons {
  width: 1200px;
  margin: 0 auto;
}
.fixed {
  width: 110px;
  height: 50px;
  line-height: 50px;
  position: fixed;
  bottom: 10px;
  right: 200px;
  font-size: 18px;
  background-color: #333333;
  border-radius: 4px;
  color: orange;
}
.el-dropdown {
  height: 100%;
  width: 120px;
}
.username {
  position: absolute;
  vertical-align: middle;
  padding-left: 10px;
}
</style>>


